package com.supercool.NutritionMe;

import java.util.HashMap;

/**
   Mimics a database to store mappings for data
    not provided by the United States Department
    of Agriculture (USDA). In particular, a mapping
    for abbreviated nutrient names to full form names.
    In addition, a mapping for full form nutrient 
    names to units.
   @author Team SuperCool
 */
public class Rectify 
{
	private HashMap<String, String> names;
	private HashMap<String, String> units;
	
	
	/**
	   Constructs a mapping for abbreviated nutrient 
	    names to full form names and abbreviated nutrient 
	    names to units
	 */
	
	public Rectify()
	{
		names = new HashMap<String, String>();
		units = new HashMap<String, String>();
		updateNames();
		updateUnits();
	}
	
	/**
	    Inserts mappings for abbreviated nutrient 
	     names to full form names. Stored in
	     private member variable.
	 */
	public void updateNames()
	{
		// names
		names.put("Water", "Water");
		names.put("Energ_Kcal", "Energy");
		names.put("Protein", "Protein");
		names.put("Lipid_Tot", "Total lipid (fat)");
		names.put("Ash", "Ash");
		names.put("Carbohydrt", "Carbohydrate, by difference");
		names.put("Fiber_TD", "Fiber, total dietary");
		names.put("Sugar_Tot", "Sugars, total");
		names.put("Calcium", "Calcium, Ca");
		names.put("Iron", "Iron, Fe");
		names.put("Magnesium", "Magnesium, Mg");
		names.put("Phosphorus", "Phosphorus, P");
		names.put("Potassium", "Potassium, K"); 
		names.put("Sodium", "Sodium, Na");
		names.put("Zinc", "Zinc, Zn");
		names.put("Copper", "Copper, Cu");
		names.put("Manganese", "Manganese, Mn");
		names.put("Selenium", "Selenium, Se");
		names.put("Vit_C", "Vitamin C, total ascorbic acid");
		names.put("Thiamin", "Thiamin");
		names.put("Riboflavin", "Riboflavin");
		names.put("Niacin", "Niacin");
		names.put("Panto_Acid", "Pantothenic acid");
		names.put("Vit_B6", "Vitamin B-6");
		names.put("Folate_Tot", "Folate, total");
		names.put("Food_Folate", "Folate, food");
		names.put("Folic_Acid", "Folic acid");
		names.put("Folate_DFE", "Folate, DFE");
		names.put("Vit_B12", "Vitamin B-12");
		names.put("Vit_A_IU", "Vitamin A, IU");
		names.put("Choline_Tot", "Choline, total");
		names.put("Vit_A_RAE", "Vitamin A, RAE");
		names.put("Retinol", "Retinol");
		names.put("Alpha_Carot", "Carotene, alpha");
		names.put("Beta_Carot", "Carotene, beta");
		names.put("Beta_Crypt", "Cryptoxanthin, beta");
		names.put("Lycopene", "Lycopene");
		names.put("Lut_Zea", "Lutein + zeaxanthin");
		names.put("Vit_E", "Vitamin E (alpha-tocopherol)");
		names.put("Vit_D_mcg", "Vitamin D3 (cholecalciferol)");
		names.put("ViVit_D_IU", "Vitamin D");
		names.put("Vit_K", "Vitamin K (phylloquinone)");
		names.put("FA_Sat", "Fatty acids, total saturated");
		names.put("FA_Mono", "Fatty acids, total monounsaturated");
		names.put("FA_Poly", "Fatty acids, total polyunsaturated");
		names.put("Cholestrl", "Cholesterol");
		names.put("Tot_Fat", "Total fat");
	}
	
	
	/**
	   Inserts mappings for full form nutrient 
	     names to units. Stored in private member 
	     variable.
	 */
	
	public void updateUnits()
	{
		units.put("Water", "g");
		units.put("Energy", "kcal");
		units.put("Protein", "g");
		units.put("Total lipid (fat)", "g");
		units.put("Ash", "g");
		units.put("Carbohydrate, by difference", "g");
		units.put("Fiber, total dietary", "g");
		units.put("Sugars, total", "g");
		units.put("Calcium, Ca", "mg");
		units.put("Iron, Fe", "mg");
		units.put("Magnesium, Mg", "mg");
		units.put("Phosphorus, P", "mg");
		units.put("Potassium, K", "mg"); 
		units.put("Sodium, Na", "mg");
		units.put("Zinc, Zn", "mg");
		units.put("Copper, Cu", "mg");
		units.put("Manganese, Mn", "mg");
		units.put("Selenium, Se", "mcg");
		units.put("Vitamin C, total ascorbic acid", "mg");
		units.put("Thiamin", "mg");
		units.put("Riboflavin", "mg");
		units.put("Niacin", "mg");
		units.put("Pantothenic acid", "mg");
		units.put("Vitamin B-6", "mg");
		units.put("Folate, total", "mcg");
		units.put("Folate, food", "mcg");
		units.put("Folic acid", "mcg");
		units.put("Folate, DFE", "mcg_DFE");
		units.put("Vitamin B-12", "mcg");
		units.put("Vitamin A, IU", "IU");
		units.put("Retinol", "mcg");
		units.put("Choline, total", "mg");
		units.put("Vitamin A, RAE", "mcg_RAE");
		units.put("Carotene, alpha", "mcg");
		units.put("Carotene, beta", "mcg");
		units.put("Cryptoxanthin, beta", "mcg");
		units.put("Lycopene", "mcg");
		units.put("Lutein + zeaxanthin", "mcg");
		units.put("Vitamin E (alpha-tocopherol)", "mg");
		units.put("Vitamin D3 (cholecalciferol)", "mcg");
		units.put("Vitamin D", "IU");
		units.put("Vitamin K (phylloquinone)", "mcg");
		units.put("Fatty acids, total saturated", "g");
		units.put("Fatty acids, total monounsaturated", "g");
		units.put("Fatty acids, total polyunsaturated", "g");
		units.put("Cholesterol", "mg");
		units.put("Total fat", "g");
	}
	
	
	/**
	   Returns the Value for Key inName.
	    Namely, the Full Form of the abbreviated
	    nutrient name.
	   @param inName abbreviated nutrient name
	   @return Full form of nutrient name 
	    if mapping exists else abbreviated name
	 */
	
	public String getName(String inName)
	{
		if (names.get(inName) != null)
			return names.get(inName);
		else 
			return inName;
	}
	
	
	/**
	   Returns the Value for Key inName.
	    Namely, the unit for the full form
	    nutrient name.
	  @param inName full form nutrient name
	  @return Unit of nutrient name if 
	   mapping exists else N/A
	 */
	public String getUnit(String inName)
	{
		if (units.get(inName) != null)
			return units.get(inName);
		else return "N/A";
	}
}
